#include <EEPROM.h>

// the current address in the EEPROM (i.e. which byte
// we're going to write to next)
int value = 5521731;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  saveInt(&value, 0);
  delay(2000);
  int i = loadInt(0);
  Serial.println(i, DEC);
  delay(10000 * 600);
}

void saveInt(int* i, int offset){
  
  byte* b = (byte*)i;
  
  for(int j = 3; j >= 0; j--){
   EEPROM.write(offset + j, *(b + j));
  }
}

void saveFloat(float* f, int offset){
  
  byte* b = (byte*)f;
  
  for(int j = 3; j >= 0; j--){
   EEPROM.write(offset + j, *(b + j));
  }
}

int loadInt(int address){
  byte* i = (byte*)malloc(4);
  int out;
  for(int j = 3; j >= 0; j--){
   byte b = EEPROM.read(address + j);
   *(i + j) = b;
  }
  
  out = *((int*)i);
  free(i);
  return out;
}

float loadFloat(int address){
  byte* i = (byte*)malloc(4);
  float out;
  for(int j = 3; j >= 0; j--){
   byte b = EEPROM.read(address + j);
   *(i + j) = b;
  }
  
  out = *((float*)i);
  free(i);
  return out;
}
